package com.ruoyi.web.controller.credit;

import java.util.List;

import com.ruoyi.common.utils.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.credit.domain.EvaTaskDetail;
import com.ruoyi.credit.service.IEvaTaskDetailService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 评价任务详情Controller
 *
 * @author zhulei
 * @date 2022-03-10
 */
@Controller
@RequestMapping("/credit/taskDetail")
public class EvaTaskDetailController extends BaseController
{
    private String prefix = "credit/taskDetail";

    @Autowired
    private IEvaTaskDetailService evaTaskDetailService;

    @RequiresPermissions("credit:taskDetail:view")
    @GetMapping()
    public String taskDetail()
    {
        return prefix + "/taskDetail";
    }

    /**
     * 查询评价任务详情列表
     */
    @RequiresPermissions("credit:taskDetail:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(EvaTaskDetail evaTaskDetail)
    {
        startPage();
        List<EvaTaskDetail> list = evaTaskDetailService.selectEvaTaskDetailList(evaTaskDetail);
        return getDataTable(list);
    }

    /**
     * 导出评价任务详情列表
     */
    @RequiresPermissions("credit:taskDetail:export")
    @Log(title = "评价任务详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(EvaTaskDetail evaTaskDetail)
    {
        List<EvaTaskDetail> list = evaTaskDetailService.selectEvaTaskDetailList(evaTaskDetail);
        ExcelUtil<EvaTaskDetail> util = new ExcelUtil<EvaTaskDetail>(EvaTaskDetail.class);
        return util.exportExcel(list, "评价任务详情数据");
    }

    /**
     * 新增评价任务详情
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存评价任务详情
     */
    @RequiresPermissions("credit:taskDetail:add")
    @Log(title = "评价任务详情", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(EvaTaskDetail evaTaskDetail)
    {
        return toAjax(evaTaskDetailService.insertEvaTaskDetail(evaTaskDetail));
    }

    /**
     * 修改评价任务详情
     */
    @RequiresPermissions("credit:taskDetail:edit")
    @GetMapping("/edit/{taskDetailId}")
    public String edit(@PathVariable("taskDetailId") Long taskDetailId, ModelMap mmap)
    {
        EvaTaskDetail evaTaskDetail = evaTaskDetailService.selectEvaTaskDetailByTaskDetailId(taskDetailId);
        mmap.put("evaTaskDetail", evaTaskDetail);
        return prefix + "/edit";
    }

    /**
     * 修改保存评价任务详情
     */
    @RequiresPermissions("credit:taskDetail:edit")
    @Log(title = "评价任务详情", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(EvaTaskDetail evaTaskDetail)
    {
        return toAjax(evaTaskDetailService.updateEvaTaskDetail(evaTaskDetail));
    }

    /**
     * 删除评价任务详情
     */
    @RequiresPermissions("credit:taskDetail:remove")
    @Log(title = "评价任务详情", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(evaTaskDetailService.deleteEvaTaskDetailByTaskDetailIds(ids));
    }

    /**
     * 查看详情页面
     */
    @GetMapping("/detail/{taskDetailId}")
    public String detail(@PathVariable("taskDetailId") Long taskDetailId, ModelMap mmap)
    {
        EvaTaskDetail evaTaskDetail = evaTaskDetailService.selectEvaTaskDetailByTaskDetailId(taskDetailId);
        mmap.put("evaTaskDetail", evaTaskDetail);
        return prefix + "/detail";
    }
}
